$(function(){
	/*layui.use('layer', function(){
	})*/
	findlist(getCookie("useriphone"),"",10)
})
var pages="";
function waithtml(num,address,createdDt,orderid,title){
	return '<a href="../weixinuser/order-details.jsp?orderid='+orderid+'">'
	+'<div class="content">'
	+'<div class="wait">'
	+'<p>'
	+'	<i class="icon iconfont icon-time"></i>'
	+'	<span>发布时间:'+createdDt+'</span>'
	+'</p>'
	+'<span class="word">待确认</span>'
	+'</div>'
	+'<div class="wait-prompt"></div>'
	+'<div class="address">'
	+'	<p>'
	+'	<span>地址:'+address+'</span>'
	+'	<span>状态:'+title+'</span>'
	+'</p>'
	+'<span class="num num-prompt">'+num+'/桶</span>'
	+'</div>'
	+'</div>'
	+'</a>'
}
function nowtml(num,address,createdDt,orderid){
	return '<a href="../weixinuser/order-details.jsp?orderid='+orderid+'">'
	+'<div class="content">'
	+'<div class="now">'
	+'<p>'
	+'	<i class="icon iconfont icon-time"></i>'
	+'	<span>发布时间:'+createdDt+'</span>'
	+'</p>'
	+'<span class="word">派送中</span>'
	+'</div>'
	+'<div class="wait-now"></div>'
	+'<div class="address">'
	+'	<p>'
	+'	<span>地址:'+address+'</span>'
	+'	<span>状态:收油车已在派送途中</span>'
	+'</p>'
	+'<span class="num num-now">'+num+'/桶</span>'
	+'</div>'
	+'</div>'
	+'</a>'
}
function finishhtml(num,address,createdDt,orderid,phone){
	return '<div class="content">'
	+'<div class="finish">'
	+'<p onclick=" finishhtmlclick('+orderid+')">'
	+'	<i class="icon iconfont icon-time"></i>'
	+'	<span>发布时间:'+createdDt+'</span>'
	+'</p>'
	+'<div class="word">'
	+'	<span>已完成</span><span class="success" onclick=comment('+phone+')>服务评价</span>'
	+'</div>'
	+'</div>'
	+'<div class="wait-finish"></div>'
	+'<div class="address">'
	+'<p>'
	+'	<span>地址:'+address+'</span>'
	+'	<span>状态:已完成</span>'
	+'	</p>'
	+'	<span class="num num-finish">'+num+'/桶</span>'
	+'</div>'
	+'</div>'
} 
function finishhtmlclick(id){
	location.href="../weixinuser/order-details.jsp?orderid="+id+""
}
function findlist(phone,orderid,roleId) {
	/*layui.use('layer', function(){
		layer.load(2, {time: 1*1000})
	})*/
	var json = {
			"filterscount": "0",
			"groupscount": "0",
			"pagenum": "0",//页数
			"pagesize": "0",//条数
			"recordstartindex": "0",
			"recordendindex": "0",
			"roleId": "10",//角色id
			"phone": "18883753989",
			"iphone": "18883753989"
	}

	layui.use('flow', function(){
		var flow = layui.flow;
		flow.load({
			elem: '.main' //流加载容器
				,done: function(page, next){ 
					var jsonstr = "filterscount=0&groupscount=0&pagenum="+(page-1)+"&pagesize=6&recordstartindex=0&recordendindex=6&roleId="+roleId+"&phone="+phone+"&iphone="+phone+"&orderid="+orderid+"";
					$.ajax({
						cache: false,
						type: "post",
						datatype: 'json',
						contentType: 'application/json;charset=UTF-8',
						data: jsonstr,
						url: ''+httpipstr+'alfa-mobile-ws/rest/order/findlist?mobiletoken='+getCookie("mobiletokenuser")+'',
						success: function(data) {
							if(orderid==""){
								if(data.total=="0"){
									$(".main").html("暂无数据");
								}else{
									var lis = [];
									if(!(data.total%6)){
										pages=data.total/6
									}else{
										pages=data.total/6+1
									}
									$.each(data.rows, function (n, value) {
										if(value.orgstatus=="2"){
											lis.push(waithtml(value.num,value.address,value.createdDt,value.orderid,"该订单已确认，收油车派送中..."));
											/*$(".content").append(waithtml(value.num,value.address,value.createdDt,value.orderid));*/
										}else if(value.orgstatus=="3"){
											lis.push(nowtml(value.num,value.address,value.createdDt,value.orderid));
											/*$(".content").append(nowtml(value.num,value.address,value.createdDt,value.orderid));*/
										}else if(value.orgstatus=="4"){
											lis.push(finishhtml((!value.realnum ||value.realnum=="undefined"? "0" : ""+value.realnum+""),value.address,value.createdDt,value.orderid,value.phone));
											/*	$(".content").append(finishhtml((!value.realnum ||value.realnum=="undefined"? "0" : ""+value.realnum+""),value.address,value.createdDt,value.orderid));*/
										}else if(value.orgstatus=="1"){
											lis.push(waithtml(value.num,value.address,value.createdDt,value.orderid,"该订单尚未确认，请稍候..."));
											/*$(".content").append(waithtml(value.num,value.address,value.createdDt,value.orderid));*/
										}
									})
									next(lis.join(''), page < pages);    

								}
							}else{
							}
						}
					});
				}
		})//执行下一页的回调
	})

}
function comment(phone){
	location.href="../weixinuser/user_Comment.jsp?phone="+phone+"";
}